package com.ruoyi.web.controller.buy;

import com.ruoyi.buy.domain.entity.PO.BuyRequestbuyBill;
import com.ruoyi.buy.domain.entity.importPO.BuyBatchPurchaseBillImport;
import com.ruoyi.buy.service.IBuyRequestbuyBillService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 请购单Controller
 * 
 * @author ruoyi
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/buy/buyRequestbuyBill")
@Transactional
public class BuyRequestbuyBillController extends BaseController
{
    @Autowired
    private IBuyRequestbuyBillService buyRequestbuyBillService;

    /**
     * 查询请购单列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BuyRequestbuyBill buyRequestbuyBill)
    {
        startPage();
        List<BuyRequestbuyBill> list = buyRequestbuyBillService.selectBuyRequestbuyBillList(buyRequestbuyBill);
        return getDataTable(list);
    }

    /**
     * 导出请购单列表
     */

    @Log(title = "请购单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyRequestbuyBill buyRequestbuyBill)
    {
        List<BuyRequestbuyBill> list = buyRequestbuyBillService.selectBuyRequestbuyBillList(buyRequestbuyBill);
        ExcelUtil<BuyRequestbuyBill> util = new ExcelUtil<BuyRequestbuyBill>(BuyRequestbuyBill.class);
        util.exportExcel(response, list, "请购单数据");
    }

    /**
     * 获取请购单详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(buyRequestbuyBillService.getInfo(id));
    }

    /**
     * 新增请购单
     */

    @Log(title = "请购单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyRequestbuyBill buyRequestbuyBill)
    {
        return toAjax(buyRequestbuyBillService.insertBuyRequestbuyBill(buyRequestbuyBill));
    }

    /**
     * 修改请购单
     */

    @Log(title = "请购单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyRequestbuyBill buyRequestbuyBill)
    {
        return toAjax(buyRequestbuyBillService.updateBuyRequestbuyBill(buyRequestbuyBill));
    }

    /**
     * 删除请购单
     */

    @Log(title = "请购单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buyRequestbuyBillService.deleteBuyRequestbuyBillByIds(ids));
    }

    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        this.buyRequestbuyBillService.importData(file);
        return toAjax(1);
    }
}
